using DukeyTbker.API;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using System.Windows.Forms;
using zoyobar.shared.panzer.web.ib;
namespace DukeyTbker {
    [ComVisible(true), PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
    public class LoginFetchFrm : Form {
        private Button btnCollect;
        private Button btnFetch;
        private Button btnGetCookie;
        private Button btnGoUrl;
        private Button btnHidden;
        private ComboBox cbType;
        private IContainer icontainer_0;
        private IEBrowser iebrowser_0;
        private SplitContainer splitContainer1;
        private TextBox txtUrl;
        private WebBrowser webBrowser;

        public LoginFetchFrm() {
            this.InitializeComponent();
            this.iebrowser_0 = new IEBrowser(this.webBrowser);
            this.cbType.SelectedIndex = 0;
        }

        private void btnCollect_Click(object sender, EventArgs e) {
            this.iebrowser_0.__Set("a", "'test'");
            switch (this.cbType.SelectedIndex) {
                case 0:
                    this.iebrowser_0.InvokeScript("Caiji");
                    break;

                case 1:
                    this.iebrowser_0.InvokeScript("CaijiTaokequn");
                    break;
            }
            string str = string.Format("{0}", this.iebrowser_0.__Get<string>("a"));
            Page page = new Page();
            page.Url = this.webBrowser.Url.AbsoluteUri;
            page.Body = str;
            Page page2 = page;
            MiddleModule.SendMessage(this, page2);
            base.Visible = false;
            this.btnCollect.Enabled = false;
            this.btnFetch.Enabled = true;
            Comm.ContainerCookies = FullWebBrowserCookie.smethod_0(new Uri(page2.Url), false);
        }

        private void btnFetch_Click(object sender, EventArgs e) {
            this.iebrowser_0.InstallScript(new Uri("http://www.mou18.com/cdn/jquery.js"));
            this.iebrowser_0.InstallScript(new Uri("http://www.mou18.com/cdn/json2.js"));
            this.iebrowser_0.InstallScript(new Uri("http://www.mou18.com/cdn/tbjyapi.js"));
            this.iebrowser_0.InstallTrace();
            this.btnCollect.Enabled = true;
            this.btnFetch.Enabled = false;
        }

        private void btnGetCookie_Click(object sender, EventArgs e) {
            Comm.ContainerCookies = FullWebBrowserCookie.smethod_0(new Uri(this.webBrowser.Url.AbsoluteUri), false);
            base.Visible = false;
        }

        private void btnGoUrl_Click(object sender, EventArgs e) {
            if (this.txtUrl.Text != "") {
                if (this.txtUrl.Text.ToLower().Contains("http://")) {
                    this.webBrowser.Url = new Uri(this.txtUrl.Text.Trim());
                }
                else {
                    this.webBrowser.Url = new Uri("http://" + this.txtUrl.Text.Trim());
                }
            }
        }

        private void btnHidden_Click(object sender, EventArgs e) {
            base.Visible = false;
        }

        protected override void Dispose(bool disposing) {
            if (disposing && (this.icontainer_0 != null)) {
                this.icontainer_0.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent() {
            this.webBrowser = new WebBrowser();
            this.btnFetch = new Button();
            this.btnHidden = new Button();
            this.splitContainer1 = new SplitContainer();
            this.btnGoUrl = new Button();
            this.txtUrl = new TextBox();
            this.cbType = new ComboBox();
            this.btnCollect = new Button();
            this.btnGetCookie = new Button();
            this.splitContainer1.Panel1.SuspendLayout();
            this.splitContainer1.Panel2.SuspendLayout();
            this.splitContainer1.SuspendLayout();
            base.SuspendLayout();
            this.webBrowser.Dock = DockStyle.Fill;
            this.webBrowser.Location = new Point(0, 0);
            this.webBrowser.MinimumSize = new Size(20, 20);
            this.webBrowser.Name = "webBrowser";
            this.webBrowser.ScriptErrorsSuppressed = true;
            this.webBrowser.Size = new Size(0x485, 0x27f);
            this.webBrowser.TabIndex = 0;
            this.webBrowser.Url = new Uri("http://pub.alimama.com/index.htm?#!/promo/self/items", UriKind.Absolute);
            this.webBrowser.NewWindow += new CancelEventHandler(this.webBrowser_NewWindow);
            this.webBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(this.webBrowser_DocumentCompleted);
            this.btnFetch.Location = new Point(0x3b8, 12);
            this.btnFetch.Name = "btnFetch";
            this.btnFetch.Size = new Size(0x4b, 0x17);
            this.btnFetch.TabIndex = 1;
            this.btnFetch.Text = "提取";
            this.btnFetch.UseVisualStyleBackColor = true;
            this.btnFetch.Click += new EventHandler(this.btnFetch_Click);
            this.btnHidden.Location = new Point(0x2b3, 12);
            this.btnHidden.Name = "btnHidden";
            this.btnHidden.Size = new Size(0x4b, 0x17);
            this.btnHidden.TabIndex = 1;
            this.btnHidden.Text = "隐藏本窗体";
            this.btnHidden.UseVisualStyleBackColor = true;
            this.btnHidden.Click += new EventHandler(this.btnHidden_Click);
            this.splitContainer1.Dock = DockStyle.Fill;
            this.splitContainer1.FixedPanel = FixedPanel.Panel1;
            this.splitContainer1.Location = new Point(0, 0);
            this.splitContainer1.Name = "splitContainer1";
            this.splitContainer1.Orientation = Orientation.Horizontal;
            this.splitContainer1.Panel1.BackColor = Color.LightSkyBlue;
            this.splitContainer1.Panel1.Controls.Add(this.btnGoUrl);
            this.splitContainer1.Panel1.Controls.Add(this.txtUrl);
            this.splitContainer1.Panel1.Controls.Add(this.cbType);
            this.splitContainer1.Panel1.Controls.Add(this.btnCollect);
            this.splitContainer1.Panel1.Controls.Add(this.btnFetch);
            this.splitContainer1.Panel1.Controls.Add(this.btnGetCookie);
            this.splitContainer1.Panel1.Controls.Add(this.btnHidden);
            this.splitContainer1.Panel2.Controls.Add(this.webBrowser);
            this.splitContainer1.Size = new Size(0x485, 0x2af);
            this.splitContainer1.SplitterDistance = 0x2c;
            this.splitContainer1.TabIndex = 2;
            this.btnGoUrl.Location = new Point(0x26b, 10);
            this.btnGoUrl.Name = "btnGoUrl";
            this.btnGoUrl.Size = new Size(0x35, 0x17);
            this.btnGoUrl.TabIndex = 6;
            this.btnGoUrl.Text = "转向";
            this.btnGoUrl.UseVisualStyleBackColor = true;
            this.btnGoUrl.Click += new EventHandler(this.btnGoUrl_Click);
            this.txtUrl.Location = new Point(0x9c, 11);
            this.txtUrl.Name = "txtUrl";
            this.txtUrl.Size = new Size(0x1cb, 0x15);
            this.txtUrl.TabIndex = 5;
            this.cbType.DropDownStyle = ComboBoxStyle.DropDownList;
            this.cbType.FormattingEnabled = true;
            this.cbType.Items.AddRange(new object[] { "阿里妈妈自助推广", "阿里妈妈淘宝客群", "淘宝U站", "淘宝店铺" });
            this.cbType.Location = new Point(0x17, 12);
            this.cbType.Name = "cbType";
            this.cbType.Size = new Size(0x79, 20);
            this.cbType.TabIndex = 4;
            this.btnCollect.Enabled = false;
            this.btnCollect.Location = new Point(0x425, 11);
            this.btnCollect.Name = "btnCollect";
            this.btnCollect.Size = new Size(0x4b, 0x17);
            this.btnCollect.TabIndex = 3;
            this.btnCollect.Text = "开始采集";
            this.btnCollect.UseVisualStyleBackColor = true;
            this.btnCollect.Click += new EventHandler(this.btnCollect_Click);
            this.btnGetCookie.AutoSize = true;
            this.btnGetCookie.Location = new Point(0x325, 12);
            this.btnGetCookie.Name = "btnGetCookie";
            this.btnGetCookie.Size = new Size(0x63, 0x17);
            this.btnGetCookie.TabIndex = 1;
            this.btnGetCookie.Text = "获取登录Cookie";
            this.btnGetCookie.UseVisualStyleBackColor = true;
            this.btnGetCookie.Click += new EventHandler(this.btnGetCookie_Click);
            base.AutoScaleDimensions = new SizeF(6f, 12f);
            //base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x485, 0x2af);
            base.Controls.Add(this.splitContainer1);
            base.Name = "LoginFetchFrm";
            base.StartPosition = FormStartPosition.CenterScreen;
            this.Text = "阿里妈妈登录";
            base.FormClosed += new FormClosedEventHandler(this.LoginFetchFrm_FormClosed);
            base.FormClosing += new FormClosingEventHandler(this.LoginFetchFrm_FormClosing);
            this.splitContainer1.Panel1.ResumeLayout(false);
            this.splitContainer1.Panel1.PerformLayout();
            this.splitContainer1.Panel2.ResumeLayout(false);
            this.splitContainer1.ResumeLayout(false);
            base.ResumeLayout(false);
        }

        private void LoginFetchFrm_FormClosed(object sender, FormClosedEventArgs e) {
        }

        private void LoginFetchFrm_FormClosing(object sender, FormClosingEventArgs e) {
            e.Cancel = true;
            base.Visible = false;
        }

        private void method_0(object object_0, object object_1) {
        }

        public object method_1(string string_0, object[] object_0) {
            return this.webBrowser.Document.InvokeScript(string_0, object_0);
        }

        private void method_2(object sender, HtmlElementErrorEventArgs e) {
            e.Handled = true;
        }

        private void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) {
            ((WebBrowser)sender).Document.Window.Error += new HtmlElementErrorEventHandler(this.method_2);
            foreach (HtmlElement element2 in this.webBrowser.Document.Links) {
                element2.SetAttribute("target", "_parent");
            }
            foreach (HtmlElement element in this.webBrowser.Document.Forms) {
                element.SetAttribute("target", "_parent");
            }
        }

        private void webBrowser_NewWindow(object sender, CancelEventArgs e) {
        }
    }
}

